<?php

namespace app\common\model\mysql;

use think\Model;

class Worker extends Model
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'wo_worker';

    /**
     * 根据手机号查找员工个人数据
     * @param $phone
     * @return array|false
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getWorkerByPhoneFind($phone){
        if(empty($phone)){
            return false;
        }
        $where = [
            ['phone','=',$phone],
            ['isdel','=',0]
        ];
        $result = $this->where($where)->find();
        return $result ? $result->toArray() : [];
    }

    /**
     * 根据主键id查找员工个人数据
     * @param $phone
     * @return array|false
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getWorkerByIdFind($id){
        if(empty($id)){
            return false;
        }
        $where = [
            ['worker_id','=',$id],
            ['isdel','=',0]
        ];
        $result = $this->where($where)->find();
        return $result ? $result->toArray() : [];
    }

    /**
     * 根据主键id更新数据表中的数据
     * @param $id
     * @param $data
     * @return bool
     */
    public function updateByWorkerId($id,$data){
        $id = intval($id);
        if(empty($id) || empty($data) || !is_array($data)){
            return false;
        }
        $where = [
            "worker_id"=>$id,
        ];
        return $this->where($where)->save($data);
    }
}
